package com.doudou.collection.infrastructure.core.security.handle;

import com.alibaba.fastjson.JSON;
import com.doudou.collection.infrastructure.common.web.ResultVO;
import com.doudou.collection.infrastructure.common.web.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName LogoutSuccessHandlerImpl<br>
 * @Description 自定义退出处理类 返回成功<br>
 * @Author 李浩文<br>
 * @Date 2023/6/30 17:36<br>
 * @Version 1.0<br>
 */
@Slf4j
@Configuration
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {

    public LogoutSuccessHandlerImpl() {
        log.debug("自定义退出处理类启动：LogoutSuccessHandlerImpl");
    }

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        String message = "退出成功！";
        ResultVO resultVO = new ResultVO(StatusCode.SUCCESS.getCode(), message);
        PrintWriter writer = response.getWriter();
        writer.println(JSON.toJSONString(resultVO));
        writer.close();
    }
}













